/*
This exercise is to understand the idea of subclasses and superclasses in java. This is also called inheritance in general. The idea is to reuse an existing class's code in the subclass.
Do as directed.
 */

//Create a class called Account
class Account {
	long balance;

	Account(long x) {
		balance = x;
	}

	// a public method called deposit(long amount) that will add amount to the
	// balance.
	long deposit(long amount) {
		balance = amount + balance;
		System.out.println("You deposit $" + amount + ".");
		return balance;
	}

	// a public method called withdraw(long amount) that will subtract amount
	// from the balance.
	long withdraw(long amount) {

		if (amount < balance) {
			balance = balance - amount;
			System.out.println("You withdraw $" + amount + ".");
			return balance;
		} else {
			System.out.println("You only have $" + balance
					+ " in your account. Please make a smaller writhdrawl.");
		}
		return balance;
	}
}

// another class called SavingsAccount (subclass) that 'extends' from the
class SavingsAccount extends Account {
	double interest = 3.5;

	SavingsAccount(long x) {
		super(x);
		// interest = 3.5;
	}

	long add_interest() {
		balance = balance + (long) (balance * (interest / 100));
		System.out.println("The interest rate is " + interest + "%.");
		return balance;
	}

	void display_balance() {
		System.out.println("You have $" + balance
				+ " in your account after interest.");
	}
}

public class Lian {

	// main method
	public static void main(String args[]) {

		long deposit_balance, withdraw_balance;

		// an instance of the subclass with initial balance 20000
		SavingsAccount account1 = new SavingsAccount(20000);
		account1.deposit(500L); // call the method deposit(500)
		account1.withdraw(3000L); // call the method withdraw(3000)
		account1.add_interest(); // call the method add_interest()
		account1.display_balance(); // call the method display_balance()

	}
}
